/**
 * Copyright (c) 2016-2019, Michael Yang 杨福海 (fuhai999@gmail.com).
 * <p>
 * Licensed under the GNU Lesser General Public License (LGPL) ,Version 3.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.gnu.org/licenses/lgpl-3.0.txt
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.jpress.module.advert.controller;

import com.jfinal.core.paragetter.Para;
import com.jfinal.kit.Ret;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.upload.UploadFile;
import io.jboot.utils.FileUtils;
import io.jboot.web.controller.JbootController;
import io.jboot.web.controller.annotation.RequestMapping;
import io.jpress.commons.utils.AttachmentUtils;
import io.jpress.model.Attachment;
import io.jpress.service.AdvertService;
import io.jpress.service.AttachmentService;
import io.jpress.service.OptionService;
import io.jpress.web.base.UserControllerBase;

import javax.inject.Inject;

/**
 * @author Michael Yang 杨福海 （fuhai999@gmail.com）
 * @version V1.0
 * @Title: 首页
 * @Package io.jpress.web.admin
 */
@RequestMapping("/advert")
public class AttachmentController extends JbootController {


    @Inject
    private AdvertService as;

    @Inject
    OptionService optionService;

//    public void index() {
//        Page<Attachment> page = as._paginate(1, 2, null);
//        renderJson(Ret.ok().set("success", true).set("page", page));
//    }

    public void BleTest(){

        int pageSize =  optionService.findAsIntegerByKey("Msb_Test");


        renderJson(Ret.ok().set("success", true).set("bletest", pageSize));
    }



  //返回最新的10张图片
    public void PageNewest(@Para("pageNo")Integer pageNo, @Para("pageSize")Integer pageSize){
        if(pageNo == null){
            pageNo = 1;
        }
        if(pageSize == null){
            pageSize =  optionService.findAsIntegerByKey("limit_newest_advert_count");
        }
        Page<Attachment> page = as._paginate_pic(pageNo, pageSize);
        renderJson(Ret.ok().set("success", true).set("page", page));
    }

    //返回所有的图片 按页查询
    public void PagePic(@Para("pageNo")Integer pageNo, @Para("pageSize")Integer pageSize){

        Page<Attachment> page = as._paginate_pic(pageNo, pageSize);
        renderJson(Ret.ok().set("success", true).set("page", page));
    }




    //返回所有的视频  按页查询


}
